import java.util.Stack;

/**
 * @author wangj881
 * @date 2024-11-26 9:34
 */
public class L232_2 {

    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        myQueue.peek();
        myQueue.pop();
        myQueue.empty();
        System.out.println(1);

    }

    static class MyQueue {
        Stack<Integer> up = new Stack<>();
        Stack<Integer> down = new Stack<>();

        public MyQueue() {
        }

        void push(int x) {
            up.push(x);
        }

        int pop() {
            deal();
            return down.pop();
        }

        boolean empty() {
            return up.empty() && down.empty();
        }

        int peek() {
            deal();
            return down.peek();
        }

        void deal() {
            if (empty()) {
                throw new RuntimeException("empty");
            }
            if (down.empty()) {
                while (!up.empty()) {
                    down.push(up.pop());
                }
            }
        }

    }
}
